/**
 * Created with IntelliJ IDEA
 * Description
 * User: 王杰
 * Date: 2025-05-15
 * Time: 21:01
 */
class Alg2 {
    public <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}

// 写一个泛型类 可以求数组最大值
class Alg<E extends Comparable<E>> {
    public E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
public class TestGeneric {
    public static void main(String[] args) {
        Integer[] array = {1,2,3,4,5,6,7,8,10};
        Alg<Integer> alg = new Alg<Integer>();
        int a = alg.findMax(array);
        System.out.println(a);

        Alg2 alg2 = new Alg2();
        int ret = alg2.findMax(array);
        System.out.println(ret);
    }
}
